package cn.xsw.controller;


import cn.xsw.common.ResultBody;
import cn.xsw.entity.Comment;
import cn.xsw.entity.query.CommentQuery;
import cn.xsw.service.CommentService;
import cn.xsw.service.impl.UserServiceImpl;
import com.baomidou.mybatisplus.core.metadata.IPage;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author liangYiHui
 * @since 2021-06-03
 */
@RestController
@RequestMapping("/comment")
@Api(tags = "评论接口")
public class CommentController {


    @Resource
    private CommentService commentService;
    @Resource
    private UserServiceImpl userService;

    @ApiOperation("分页条件查询")
    @GetMapping("/findPage")
    public ResultBody findPage(CommentQuery query){
        IPage pageVo = commentService.findPageVo(query);
        return ResultBody.success().page(pageVo);
    }


    @ApiOperation("根据id删除")
    @GetMapping("/delById/{id}")
    public ResultBody delById(@PathVariable("id") int id){
        Boolean b = commentService.removeById(id);
        if(!b) return ResultBody.error("删除失败");
        return ResultBody.success();
    }



    @ApiOperation("添加或更新（对象id为空：添加，对象id不为空：编辑）")
    @PostMapping("/saveOrUpdate")
    public ResultBody saveOrUpdate(Comment comment){
        Boolean b = commentService.saveOrUpdate(comment);
        if(!b) return ResultBody.error("操作失败");
        return ResultBody.success();
    }
}

